<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>">
<%@include file="/views/global/ShopInclude.jsp" %>
<link rel="stylesheet" type="text/css" href="static/bootstrap/css/bootstrap.css">
<link href="static/css/module/cart.css" rel="stylesheet" type="text/css">
<title>ADDRESS</title>
</head>
<body>
<div class="form-container center font">
	<div class="cart-title">确认收货信息</div>
	<!-- 表单填写部分 -->
	<div id="msg"></div>
	<c:if test="${not empty entityList }">
	<div class="control-label">
		<div class="row" style="padding-left: 50px;">
			<div class="pull-left">
				已保存的收货地址
			</div>
			<div class="pull-right" style="padding-right: 40px;">
				<a href="buyer/address" target="_blank">管理收货地址</a>
			</div>
		</div>
	</div>
	</c:if>
	<form id="submitForm" name="submitForm" class="validate" action="buyer/cart/submitAddress" method="post" style="padding-left: 50px;">
    	<input type="hidden" name="mobileArea" value="086"/>
		<textarea rows="4" cols="50" name="strCartItems" style="display:none">${strCartItems }</textarea>
		<ul class="row address-list">
			<c:forEach var="item" items="${entityList }">
				<li>
					<input type="radio" class="radio" name="addressId" value="${item.id }" style="width: 20px;margin-top: 0;" />
					${item.userName }&nbsp;&nbsp;(${item.mobileArea }&nbsp;${item.mobilePhone })
					${item.countryName },&nbsp;${item.stateName },&nbsp;${item.cityName },&nbsp;${item.district } &nbsp;&nbsp;
					${item.street }&nbsp;&nbsp;
				</li>
			</c:forEach>
			<li>
				<input type="radio" class="radio" name="addressId" value="0" style="width: 20px;margin-top: 0;" />&nbsp;使用新地址
			</li>
		</ul>
		<div style="width: 800px;">
		<div class="row">
			<div class="form-inline address-group" style="margin-bottom: 10px;">
				<select class="form-control" name="countryId" id="countryId" lang="zh_CN">
   				</select>
   				<select class="form-control" name="stateId" id="stateId" required="true">
   					<option value="">&nbsp;</option>
   				</select>
   				<select class="form-control" name="cityId" id="cityId">
   					<option value="">&nbsp;</option>
   				</select>
   				<input type="hidden" name="countryName" value="${area.countryName }"/>
   				<input type="hidden" name="stateName" value="${area.stateName }"/>
   				<input type="hidden" name="cityName" value="${area.cityName }"/>
			</div>
			<input type="text" class="form-control left" id="street" name="street" 
				 placeholder="街道地址" required="街道地址不能为空" style="width: 585px;"/>
			<span class="error left"></span>
		</div>
		<div class="row">
			<div class="col-xs-10" style="padding-left: 0;">
				<label class="left row" for="userName">收件人</label>
				<input type="text" class="form-control left" id="userName" name="userName" style="width: 240px;"
					placeholder="" required="收件人不能为空" maxlength="20" />
				<span class="error left"></span>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-10" style="padding-left: 0;">
				<label class="left row" for="mobilePhone">手机号码</label>
				<input type="text" class="form-control left" id="mobilePhone" name="mobilePhone" style="width: 240px;"
						 placeholder="" size="30" maxlength="20"/>
				<span class="error left"></span>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-10" style="padding-left: 0;">
				<label class="left row" for="zipCode">邮政编码</label>
				<input type="text" class="form-control left" id="postalCode" name="postalCode" style="width: 240px;"
						 placeholder="" size="30" maxlength="20"/>
				<span class="error left"></span>
			</div>
		</div>
		<div class="row">
			<button type="button" class="btn btn-green" onclick="submitAddress(this)" style="line-height: 1.8;margin-top: 20px;">确认收货信息</button>
		</div>
		</div>
	</form>
  </div>
  <div class="clearfix" style="height:20px;"></div>
</body>
<%@include file="/views/global/AdminScripts.jsp" %>
<script type="text/javascript" src="static/javascript/module/area.js"></script>
<script type="text/javascript" src="static/javascript/module/CartCommon.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	initCountryList(function(){
		$("#countryId").val("${entity.countryId }");
		updateStateList(function(){
			$("#stateId").val("${entity.stateId }");
			updateCityList(function(){$("#cityId").val("${entity.cityId }");});
		});
	});
	
	$("INPUT[name='addressId']").eq(0).attr("checked", "checked");
});

function submitAddress(target){
	var addressId = $("INPUT[name='addressId']:checked").val();
	var form = $("#submitForm");
	if(0 == addressId){
		var validator = $(form).validate({meta:"validate"});
		if(!validator.form()){
			return false;
		}
	}
		
	$("input[name='countryName']").val($("#countryId").find("option:selected").html());
	$("input[name='stateName']").val($("#stateId").find("option:selected").html());
	$("input[name='cityName']").val($("#cityId").find("option:selected").html());
	document.forms["submitForm"].submit();
}
</script>
</html>
